#ifndef __DKGL_MESH_H__
#define __DKGL_MESH_H__

#include "dkglDrawable.h"
#include "dkglBuffer.h"
#include "dkglMaterial.h"

#include <boost/shared_ptr.hpp>

namespace DKGL
{
	class Mesh;

	typedef boost::shared_ptr<Mesh> MeshPtr;
	typedef std::vector<boost::any> Arguments;

	class MeshCreator
	{
	public:

		virtual MeshPtr create(const String& name, const Arguments&) = 0;
	};

    class Mesh : public Drawable
    {
    public:

        Mesh(const String&);

        virtual ~Mesh();

		virtual void setMaterial(int, MaterialPtr)
		{}

    protected:

        Buffer::BufferFloat3    vertexBuf;
        Buffer::BufferFloat3    normalBuf;
        Buffer::BufferFloat2  texcoordBuf;

        void renderImpl();

    private:
    };

	class MeshFactory
	{
	public:

		MeshFactory();

		~MeshFactory();

		void registerCreator(const String& type, std::auto_ptr<MeshCreator> creator);

		MeshPtr create(const String& type, const String& name, const Arguments&);

		static MeshFactory& instance()
		{
			static MeshFactory _instance;
			return _instance;
		}

	private:

		std::map<String, std::auto_ptr<MeshCreator> > _creators;

	};
}

#endif